/*
https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/solution/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-by-leetcode/
 */
import java.util.Arrays;

public class SolutionOffer56I {
    public int[] singleNumbers(int[] nums) {
        int t=0;
        for (int num : nums) {
            t^=num;
        }
        int rec=-1;
        for (int i=0;i<32;i++){
            if ((t&(1<<i))>0){
                rec=i;
            }
        }
        int a=0,b=0;
        for (int num : nums) {
            if ((num&(1<<rec))==0){
                a^=num;
            }else{
                b^=num;
            }
        }
        return new int[]{a,b};
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new SolutionOffer56I().singleNumbers(new int[]{4, 1, 4, 6})));
    }
}
